﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ITSTOREBLL;
using ITStore.ViewModels;

namespace ITStore.Controllers
{
    public class SanPhamBanChayController : Controller
    {
        //
        // GET: /SanPhamBanChay/
        private ITStoreEntities db = new ITStoreEntities();
        public ActionResult Index()
        {
            IEnumerable<SanPhamBanChayViewMoDel> spbc = (from p in db.ChiTietDonHangs
                        group p by new { p.ctdh_SanPham,p.ctdh_SoLuong,p.SanPham.sp_Ten,p.ctdh_Gia } into k
                        orderby k.Sum(p => p.ctdh_SoLuong) descending
                        select new SanPhamBanChayViewMoDel{ SoLuong = k.Sum(p => p.ctdh_SoLuong),TenSanPham = k.Key.sp_Ten,TongTien = k.Sum(p => p.ctdh_Gia)}).Take(10);
            return View(spbc.ToList());
        }

    }
}
